import { useState, useCallback } from 'react';

/**
 * Select Hook
 * 用于管理下拉选择对话框
 */
export const useSelect = () => {
  const [selectState, setSelectState] = useState(null);

  const showSelect = useCallback(({
    title = '选择',
    message = '',
    options = [],
    defaultValue = ''
  }) => {
    return new Promise((resolve) => {
      setSelectState({
        title,
        message,
        options,
        defaultValue,
        onConfirm: (value) => {
          setSelectState(null);
          resolve(value);
        },
        onCancel: () => {
          setSelectState(null);
          resolve(null);
        }
      });
    });
  }, []);

  return {
    selectState,
    showSelect
  };
};

